<?php

/**
 * This is the model class for table "gn_products".
 *
 * The followings are the available columns in table 'gn_products':
 * @property integer $product_id
 * @property string $product_name
 * @property string $description
 * @property double $cost_price
 * @property double $retail_price
 * @property integer $bv_points
 * @property string $dt_created
 */
class Products extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Products the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'gn_products';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('product_name, cost_price, retail_price, bv_points', 'required'),
			//array('bv_points', 'numerical', 'integerOnly'=>true),
			array('cost_price, retail_price', 'numerical'),
			array('product_name, description', 'length', 'max'=>45),
			array('dt_created', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('product_id, product_name, description, cost_price, retail_price, bv_points, dt_created', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'product_id' => 'Product',
			'product_name' => 'Product Name',
			'description' => 'Description',
			'cost_price' => 'Cost Price',
			'retail_price' => 'Retail Price',
			'bv_points' => 'Bv Points',
			'dt_created' => 'Dt Created',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('product_id',$this->product_id);
		$criteria->compare('product_name',$this->product_name,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('cost_price',$this->cost_price);
		$criteria->compare('retail_price',$this->retail_price);
		$criteria->compare('bv_points',$this->bv_points);
		$criteria->compare('dt_created',$this->dt_created,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}